from flask import Flask, g
from MySqlClient import MysqlClient, TestProxy
from getproxy import Proxy
from award import Award

__all__ = ['app']
app = Flask(__name__)


def get_conn():
    if not hasattr(g, 'mysql'):
        g.mysql = MysqlClient()
    return g.mysql


@app.route("/")
def index():
    return '<h2>Weclome to Proxy Pool System</h2>'


@app.route("/addProxy")
def addProxy():
    proxy = Proxy()
    proxy.add_proxy()
    mysql = MysqlClient()
    random_proxy = mysql.random_proxy()
    return random_proxy


@app.route("/checkProxy")
def checkProxy():
    test = TestProxy()
    test.run()
    return "success checked"


@app.route("/award")
def award():
    award = Award()
    award.start_award()
    return 'success>'


if __name__ == '__main__':
    # app.run('0.0.0.0', 5000, debug=True)
    app.run()
